package leetcode.code1620;

import leetcode.IDebug;
import leetcode.helper.H;

//1620. 网络信号最好的坐标
//欧几里得距离
public class Solution implements IDebug {

	public int[] bestCoordinate(int[][] towers, int radius) {
		int len = towers.length;
		int max = 0, x = 0, y = 0;
		for (int i = 0; i <= 50; i++) {
			int xi = i;
			for (int k = 0; k <= 50; k++) {
				int yi = k;
				int cur = 0;
				for (int j = 0; j < len; j++) {
					int xj = towers[j][0], yj = towers[j][1], qj = towers[j][2];
					int d = (xi - xj) * (xi - xj) + (yi - yj) * (yi - yj);
					if (d <= radius * radius) {
						cur += qj / (1 + Math.sqrt(d));
					}
				}
				if (cur > max || (cur == max && (xi < x || (xi == x && yi < y)))) {
					max = cur;
					x = xi;
					y = yi;
				}
			}
		}
		return new int[] { x, y };
	}

	@Override
	public void debug4() {
		this.bestCoordinate(H.str2array1("[[44,31,4],[47,27,27],[7,13,0],[13,21,20],[50,34,18],[47,44,28]]"), 13);
		this.bestCoordinate(H.str2array1("[[47,27,27],[47,44,28]]"), 13);
		this.bestCoordinate(H.str2array1("[[23,11,21]]"), 9);
		this.bestCoordinate(H.str2array1("[[42,0,0]]"), 7);

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
